#include "e2d/ui/GameLayer.h"
#include "e2d/ui/State.h"
#include "e2d/imgui/Editor.h"

#include "e2d/core/components.h"

e2d::GameLayer::GameLayer()
	:fxcc::imgui::Layer("Game Layer")
{

}

void e2d::GameLayer::SetInst(std::shared_ptr<e2d::Scene> scene)
{
	m_Scene = scene;
}

void e2d::GameLayer::ViewFunc()
{
	auto& sg = e2d::State::Inst();

	if (!m_Scene)
	{
		return;
	}

	auto& io = ImGui::GetIO();
	io.ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;

	ImVec2 m_ContentRegionAvail = ImGui::GetContentRegionAvail();
	ImVec2 contentPos = ImGui::GetCursorScreenPos();

	auto mainCameraObjMap = m_Scene->m_MainCamera;
	auto mainCameraObj = m_Scene->m_MainCamera.m_Entity;

	if (mainCameraObj && mainCameraObj->HasComponent<e2d::CameraView>())
	{
		auto& cameraViewObj = mainCameraObj;
		auto& cameraView = cameraViewObj->Get<e2d::CameraView>();
		auto& cameraTransform = cameraViewObj->GetConst<e2d::TransformNode>();

		const auto& cameraProjMartix = cameraView.GetProjMatrix();
		const auto& cameraViewMartix = cameraTransform.m_World.GetViewMatrix();

		auto rt = cameraView.m_RenderTarget;

		auto texture = cameraView.GetTextureEditing();

		m_Editor.AddFrameBuffer(texture->GetTextureId());

	}

	ImGui::SetNextItemWidth(200);
	e2d::CustomEditor::ComboEditEntity("camera Main", m_Scene->m_MainCamera, m_Scene->GetComponentEntitiesMap<e2d::CameraView>());

	io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;

}
void e2d::GameLayer::HandleFunc()
{
}
;